Attribute VB_Name = "modManipulate"
Public Sub reorderUsers(ByVal vnString As String)
  Dim arrMods() As String
  Dim arrAdmin() As String
  Dim arrRegular() As String
  
  Dim finalStr As String
  
  vnArray = Split(vnString, ", ")
  
  ReDim arrMods(0): ReDim arrAdmin(0): ReDim arrRegular(0)
  
  For i = 0 To UBound(vnArray)
    If Left(vnArray(i), 1) = "%" Then
      arrAdmin(UBound(arrAdmin)) = Mid(vnArray(i), 2)
      ReDim Preserve arrAdmin(UBound(arrAdmin) + 1)
      dicUserGroup.Item(Mid(vnArray(i), 2)) = "admin"
    ElseIf Left(vnArray(i), 1) = "@" Then
      arrMods(UBound(arrMods)) = Mid(vnArray(i), 2)
      ReDim Preserve arrMods(UBound(arrMods) + 1)
      dicUserGroup.Item(Mid(vnArray(i), 2)) = "moderator"
    Else
      arrRegular(UBound(arrRegular)) = vnArray(i)
      ReDim Preserve arrRegular(UBound(arrRegular) + 1)
      dicUserGroup.Item(vnArray(i)) = "regular"
    End If
  Next
  
  For i = 0 To UBound(arrAdmin)
    If arrAdmin(i) <> vbNullString Then
      frmChat.ChanList.ListItems.Add , , arrAdmin(i), , 1
    End If
  Next
  
  For i = 0 To UBound(arrMods)
    If arrMods(i) <> vbNullString Then
      frmChat.ChanList.ListItems.Add , , arrMods(i), , 2
    End If
  Next
  
  For i = 0 To UBound(arrRegular)
    If arrRegular(i) <> vbNullString Then
      frmChat.ChanList.ListItems.Add , , arrRegular(i), , 3
    End If
  Next
End Sub

Public Function JoinB(ByRef arr() As String, Optional joinWith As String = "") As String
  Dim str As String
  
  For i = 0 To UBound(arr)
    If arr(i) <> "" Then
      str = str & arr(i) & joinWith
    End If
  Next
  If Len(str) > Len(joinWith) Then str = Left(str, Len(str) - Len(joinWith))

  JoinB = str
End Function

Public Sub addUserToList(ByVal addUser As String)
  Dim arrMods() As String
  Dim arrAdmin() As String
  Dim arrRegular() As String
 
  Dim isAdmin As Boolean, isMod As Boolean, isRegular As Boolean
  
  frmChat.ChanList.ListItems.Clear
  
  Select Case Left(addUser, 1)
    Case "%"
      isAdmin = True
    Case "@"
      isMod = True
    Case Else
      isRegular = True
  End Select
 
  ReDim arrMods(0): ReDim arrAdmin(0): ReDim arrRegular(0)
  
  For Each key In dicUserGroup.keys
    GetUser = key
    getGroup = dicUserGroup.Item(key)
    
    If getGroup = "admin" Then
      arrAdmin(UBound(arrAdmin)) = GetUser
      ReDim Preserve arrAdmin(UBound(arrAdmin) + 1)
    ElseIf getGroup = "moderator" Then
      arrMods(UBound(arrMods)) = GetUser
      ReDim Preserve arrMods(UBound(arrMods) + 1)
    Else
      arrRegular(UBound(arrRegular)) = GetUser
      ReDim Preserve arrRegular(UBound(arrRegular) + 1)
    End If
  Next
  
  For i = 0 To UBound(arrAdmin)
    If arrAdmin(i) <> vbNullString Then
      frmChat.ChanList.ListItems.Add , , arrAdmin(i), , 1
    End If
  Next
  
  If isAdmin Then
    frmChat.ChanList.ListItems.Add , , remSpecial(addUser), , 1
    dicUserGroup.Item(addUser) = "admin"
  End If
  
  For i = 0 To UBound(arrMods)
    If arrMods(i) <> vbNullString Then
      frmChat.ChanList.ListItems.Add , , arrMods(i), , 2
    End If
  Next
  
  If isMod Then
    frmChat.ChanList.ListItems.Add , , remSpecial(addUser), , 2
    dicUserGroup.Item(addUser) = "moderator"
  End If
  
  For i = 0 To UBound(arrRegular)
    If arrRegular(i) <> vbNullString Then
      frmChat.ChanList.ListItems.Add , , arrRegular(i), , 3
    End If
  Next
 
  If isRegular Then
    frmChat.ChanList.ListItems.Add , , addUser, , 3
    dicUserGroup.Item(addUser) = "regular"
  End If
  
  frmChat.txtChannel.text = currentChannel & " (" & frmChat.ChanList.ListItems.Count & ")"
End Sub

Public Sub addToUserList()
  Dim arrAdmin() As String, arrMods() As String, arrRegular() As String
  Dim aA As Integer, aM As Integer, aR As Integer
  
  aA = 0: aM = 0: aR = 0
  ReDim arrAdmin(0), arrMods(0), arrRegular(0)
  
  
  For Each key In dicUserGroup.keys
    Select Case dicUserGroup.Item(key)
      Case "admin"
                    ReDim Preserve arrAdmin(aA)
                    arrAdmin(aA) = key
                    aA = aA + 1
      Case "moderator"
                    ReDim Preserve arrMods(aM)
                    arrMods(aM) = key
                    aM = aM + 1
      Case Else
                    ReDim Preserve arrRegular(aR)
                    arrRegular(aR) = key
                    aR = aR + 1
    End Select
  Next
  
  For Each elem In arrAdmin
    If elem = vbNullString Then Exit For
    frmChat.ChanList.ListItems.Add , , elem, , 1
  Next
  
  For Each elem In arrMods
    If elem = vbNullString Then Exit For
    frmChat.ChanList.ListItems.Add , , elem, , 2
  Next
  
  For Each elem In arrRegular
    If elem = vbNullString Then Exit For
    frmChat.ChanList.ListItems.Add , , elem, , 3
  Next
End Sub

Public Function remSpecial(ByVal str As String) As String
  str = Replace(str, "%", "")
  str = Replace(str, "@", "")
  
  remSpecial = str
End Function
